/* Copyright (c) 2010, mitsuhisa.net
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above
 *       copyright notice, this list of conditions and the following
 *       disclaimer in the documentation and/or other materials provided
 *       with the distribution.
 *     * Neither the name of the misuhisa.net nor the names of its
 *       contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef OBJECT_HPP_
#define OBJECT_HPP_

#include <vector>
#include "HeapObject.hpp"
#include "Value.hpp"
#include "Hash.hpp"

namespace nyu {

class Context;
class String;
class Object : public HeapObject {
protected:
    typedef std::vector<Value> slots_type;
    typedef Hash<Value, slots_type::size_type> hash_type;

public:
    typedef hash_type::code_type hash_code_type;

    virtual Value getSlot(Value name, Context& c) = 0;
    virtual void putSlot(Value name, Value value, Context& c) = 0;

    Value getSlot(const char* name, Context& c);
    Value getSlot(Object* name, Context& c);

    virtual hash_code_type hash();
    virtual hash_code_type hash(Context& c);

    virtual bool isTrue(Context& c);
    virtual String* toString(Context& c);
    virtual int_type toIntval(Context& c);

    virtual Value toInt(Context& c);

    virtual Value opCall(Context& c, bool is_tail = false);

    virtual Value opAdd(Value v, Context& c, bool is_tail = false);
    virtual Value opSub(Value v, Context& c, bool is_tail = false);
    virtual Value opMul(Value v, Context& c, bool is_tail = false);
    virtual Value opDiv(Value v, Context& c, bool is_tail = false);
    virtual Value opMod(Value v, Context& c, bool is_tail = false);
    virtual Value opLShift(Value v, Context& c, bool is_tail = false);
    virtual Value opRShift(Value v, Context& c, bool is_tail = false);
    virtual Value opOr(Value v, Context& c, bool is_tail = false);
    virtual Value opXor(Value v, Context& c, bool is_tail = false);
    virtual Value opAnd(Value v, Context& c, bool is_tail = false);

    virtual bool opEq(Value v, Context& c, bool is_tail = false);
    virtual bool opNe(Value v, Context& c, bool is_tail = false);
    virtual bool opLt(Value v, Context& c, bool is_tail = false);
    virtual bool opLe(Value v, Context& c, bool is_tail = false);
    virtual bool opGt(Value v, Context& c, bool is_tail = false);
    virtual bool opGe(Value v, Context& c, bool is_tail = false);

    virtual Value opIAdd(Value name, Value v, Context& c, bool is_tail = false);

    virtual Value opGetItem(Value idx, Context& c, bool is_tail = false);

    virtual int_type length(Context& c);
    virtual Value push(Context& c);
    virtual Value pop(Context& c);
    virtual Value each(Context& c);

    virtual bool revOpEq(String* other, Context& c, bool is_tail = false);

protected:
    Object();
    virtual ~Object();
};

}

#endif /* OBJECT_HPP_ */
